package com.huike.web.controller.system;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huike.clues.MpService.MpSysDictTypeService;
import com.huike.clues.domain.dto.MPSysDictTypeDTO;
import com.huike.clues.domain.result.PageResult;
import com.huike.common.constant.HttpStatus;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysDictType;
import com.huike.common.core.page.PageDomain;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.core.page.TableSupport;
import com.huike.common.entity.MPSysDictType;
import com.huike.common.utils.StringUtils;
import com.huike.common.utils.sql.SqlUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.github.pagehelper.page.PageMethod.startPage;

@RestController
@Slf4j
@Api(tags = "数据字典类型信息相关接口")
@RequestMapping("/system/dict/type")
public class SysDictTypeController extends BaseController {

    @Autowired
    private MpSysDictTypeService mpSysDictTypeService;
    /**
     * 新增字典类型
     * @param mpSysDictTypeDTO
     * @return
     */
    @PostMapping
    public AjaxResult type(@RequestBody MPSysDictTypeDTO mpSysDictTypeDTO){
        mpSysDictTypeService.addType(mpSysDictTypeDTO);
        return AjaxResult.success();
    }

    /**
     * 修改字典类型
     * @param mpSysDictType
     * @return
     */
    @PutMapping
    public AjaxResult updateType(@RequestBody MPSysDictType mpSysDictType){
        mpSysDictTypeService.updateType(mpSysDictType);
        return AjaxResult.success();
    }

    /**
     * 获取字典选择框列表
     * @return
     */
    @GetMapping("/optionselect")
    public AjaxResult optionselect(){
        List<MPSysDictType> mpSysDictTypeList = mpSysDictTypeService.optionselect();
        return AjaxResult.success(mpSysDictTypeList);
    }

    /**
     * 删除字典类型
     * @param dictIds
     * @return
     */
    @DeleteMapping("/{dictIds}")
    public AjaxResult deleteType(@PathVariable List<Long> dictIds){
        mpSysDictTypeService.deleteType(dictIds);
        return AjaxResult.success();
    }

    /**
     * 查询字典类型详细
     * @param dictId
     * @return
     */
    @GetMapping("/{dictId}")
    public AjaxResult findType(@PathVariable Long dictId){
        MPSysDictType mpSysDictType = mpSysDictTypeService.findType(dictId);
        return AjaxResult.success(mpSysDictType);
    }

    /**
     * 分页查询数据字典类型信息
     * @param mpSysDictType
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(MPSysDictType mpSysDictType){
        startPage();
        List<MPSysDictType> mpSysDictTypes = mpSysDictTypeService.pageList(mpSysDictType);
        return getDataTable(mpSysDictTypes);

    }


}
